/*
 * GameResultMapper.java
 * Copyright(C) trythis.cn
 * 2022年12月17日 19时46分25秒Created
 */
package com.njcb.game.repository.dao.mapper;

import com.njcb.ams.repository.dao.mapper.BaseMapper;
import com.njcb.game.repository.entity.GameResult;
import com.njcb.game.repository.entity.GameResultExample;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
public interface GameResultMapper extends BaseMapper<GameResult, GameResultExample, Integer> {
    @Select("\n" +
            "select r.runners_no as runnersNo,\n" +
            "       r.runners_name as runnersName,\n" +
            "       sum(r.score) as score\n" +
            "  from game_result r\n" +
            " where r.check_result = '1'\n" +
            " group by r.runners_no, r.runners_name\n" +
            " order by sum(r.score) desc\n")
    List<GameResult> selectResultWithScore();

    @Select("select gr.runners_no as runnersNo,\n" +
            "       gr.runners_name as runnersName,\n" +
            "       gr.ques_no as quesNo,\n" +
            "       gr.ques_title as quesTitle,\n" +
            "       gr.score\n" +
            "  from game_register rt, game_result gr\n" +
            " where rt.runners_no = gr.runners_no\n" +
            "   and rt.token = #{token} ")
    List<GameResult> selectDetailsByToken(@Param("token") String token);
}